﻿<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="utf-8" %>


<link rel="stylesheet" type="text/css" href="${staticPath}/base/ztree/css/zTreeStyle.css">
<script type="text/javascript" src="${staticPath}/base/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${staticPath}/base/ztree/js/jquery.ztree.excheck.js"></script>
<form id="form1">
    <div class='myzh_right_content fr'>
        <p class='right_head_title'><span class="span1">我的 ></span> 操作</p>
        <div class="recharge-content">
            <input type="hidden" id="role_id" name="role_id" value="${data.role_id}"/>

            <div class="mt-10">
                <span class="fl mt-3 w-120">角色名称：</span>
                <input type="text" class="txt txt-1 fl w-220" id="role_name" name="role_name" value="${data.role_name}">
                <div class="cl"></div>
            </div>
            <div class="mt-10">
                <span class="fl mt-3 w-120">备注：</span>
                <input type="text" class="txt txt-1 fl w-220" id="memo" name="memo" value="${data.memo}">
                <div class="cl"></div>
            </div>

            <div class="mt-10">
                <span class="fl mt-3 w-120">
                    菜单名称：
                    <ul id="ztree" class="ztree"></ul>
                </span>
                <div class="cl"></div>
            </div>
            <div class="mt-30 ml-10">
                <input type="button" class="btn btn-1 fl w-100" value="${title}" onclick="add()">
                <input type="button" class="btn btn-2 fl w-100 ml-20" value="返回"
                       onclick="window.location='${basePath}/t_role_info/list'">
            </div>
        </div>
    </div>
</form>
<div class='clear'></div>
<script type="text/javascript">
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    var zNodes = [
        ${tree_data}
    ];
    $(document).ready(function () {
        $.fn.zTree.init($("#ztree"), setting, zNodes);
    });

    function add() {

        var role_name = $("#role_name").val();
        if(role_name==""){alert("角色名称不能为空");return;}
        var zTree = $.fn.zTree.getZTreeObj("ztree");
        checkCount = zTree.getCheckedNodes(true);
        var nodes = "";
        for (var i = 0; i < checkCount.length; i++) {
            nodes += "," + checkCount[i].id
        }
        $.post("${basePath}/ajax/t_role_info/add",{role_id:$("#role_id").val(),role_name:role_name,memo:$("#memo").val(),menu_ids:nodes} , function (d) {
            if (d.code == 1) {
                alert("成功");
                window.location = "${basePath}/t_role_info/list";
                return;
            } else if (d.code == 2) {
                alert("当前角色名称已存在，请更新一个");
                return;
            }
            alert("失败");
        });
    }
</script>


